<?php
/**
 * Warehouse.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-05-11 16:38:13
 * @modified    2023-05-11 16:38:13
 *
 */

namespace App\Models;

use App\Models\Warehouse\Dept;

class Warehouse extends BaseModel
{
    protected $table = 'warehouse';
    protected $primaryKey = 'id';

    protected $fillable = [
        'name',
        'w_number',
        'province_id',
        'province_name',
        'city_id',
        'city_name',
        'county_id',
        'county_name',
        'address',
        'create_user_id'
    ];

    public function scopeByName($query, $name)
    {
        return $query->where('name', $name);
    }

    public function scopeByNumber($query, $number)
    {
        return $query->where('w_number', $number);
    }

    public function depts()
    {
        return $this->hasMany(Dept::class);
    }

    public function users()
    {
        return $this->hasMany(\App\Models\Warehouse\User::class);
    }
}